samplesDialog <- function (){
	require(TeachingExtras)
	initializeDialog(title = gettext("Samples generator", domain="R-RcmdrPlugin.TeachingExtras"))
	onOK <- function() {
		
		if (tclvalue(name) == "") {
			errorCondition(recall = samplesDialog, message = gettext("You must enter a name for the data frame.", domain="R-RcmdrPlugin.TeachingExtras"))
			return()
		}
		if (tclvalue(values) == "") {
			errorCondition(recall = samplesDialog, message = gettext("You must enter a list of values to choose.", domain="R-RcmdrPlugin.TeachingExtras"))
			return()
		}
		sums <- tclvalue(sumsVariable) == "1"
		means <- tclvalue(meansVariable) == "1"
		command <- paste(tclvalue(name), " <- samples(c(", tclvalue(values), "), nsamples=",  tclvalue(nsamples), ", size=", tclvalue(size), ", sums=", sums, ", means=", means, ")", sep = "")
		doItAndPrint(command)
		closeDialog()
		activateMenus()
		tkfocus(CommanderWindow())
	}
	OKCancelHelp(helpSubject = "samples")
	nameFrame <- tkframe(top)
	name <- tclVar("")
	nameField <- tkentry(nameFrame, width = "20", textvariable = name)
	tkgrid(tklabel(nameFrame, text = gettext("Data frame name: ", domain="R-RcmdrPlugin.TeachingExtras")), nameField, sticky = "w")
	tkgrid(nameFrame, sticky = "w")
	optionsFrame <- tkframe(top)
	values <- tclVar("")
	valuesField <- tkentry(optionsFrame, width = "10", textvariable = values)
	tkgrid(labelRcmdr(optionsFrame, text=gettext("Values to choose: ", domain="R-RcmdrPlugin.TeachingExtras")),valuesField, sticky = "w")
	nsamples <- tclVar("1")
	nsamplesField <- tkentry(optionsFrame, width = "10", textvariable = nsamples)
	tkgrid(labelRcmdr(optionsFrame, text=gettext("Number of samples: ", domain="R-RcmdrPlugin.TeachingExtras")),nsamplesField, sticky = "w")
	size <- tclVar("1")
	sizeField <- tkentry(optionsFrame, width = "10", textvariable = size)
	tkgrid(labelRcmdr(optionsFrame, text=gettext("Samples size: ", domain="R-RcmdrPlugin.TeachingExtras")),sizeField, sticky = "w")
	sumsVariable <- tclVar("0")
	sumsCheckBox <- tkcheckbutton(optionsFrame, variable = sumsVariable)
	meansVariable <- tclVar("0")
	meansCheckBox <- tkcheckbutton(optionsFrame, variable = meansVariable)
	tkgrid(tklabel(optionsFrame, text = gettext("Calculate sums", domain="R-RcmdrPlugin.TeachingExtras"), justify = "left"), sumsCheckBox, 
			tklabel(optionsFrame, text = gettext("Calculate means", domain="R-RcmdrPlugin.TeachingExtras"), justify = "left"), meansCheckBox, sticky = "w")
	tkgrid(optionsFrame, sticky="w")
	tkgrid(buttonsFrame, sticky = "w")
	dialogSuffix(rows = 3, columns = 1)
}

